package com.tuanzi.loan.web.bean.banana;

import com.tuanzi.loan.business.entity.banana.LoanBananaBindCardAction;
import com.tuanzi.loan.business.service.banana.LoanBananaBindCardActionService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.web.configuration.JSFInfoBean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;

/**
 * @author administrator
 * @createTime 2019-06-13 20:06
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class LoanBananaBindCardActionInfoBean extends JSFInfoBean<LoanBananaBindCardAction> {
    @Autowired
    private LoanBananaBindCardActionService loanBananaBindCardActionService;
    @PostConstruct
    private void init() {
        //生效时间设置
        String id = getParamFromRequest("id");
        if (StringUtils.isNotBlank(id)) {
            $ = loanBananaBindCardActionService.findOne(Long.parseLong(id));
        } else {
            $ = new LoanBananaBindCardAction();
            changeStatusToAdd();
        }
    }

    public void onSave(){
        loanBananaBindCardActionService.saveOrUpdate($);
        addSuccessfullyMessage();
        changeStatusToView();
    }
}
